/**
 * 
 */
package xiaojian.toolkit.bean.tlv.decode.decoders;

import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import xiaojian.toolkit.bean.tlv.decode.TLVDecodeContext;
import xiaojian.toolkit.bean.tlv.decode.TLVDecoder;


/**
 * @author hp
 *
 */
public class ByteArrayTLVDecoder implements TLVDecoder {

    @SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(ByteArrayTLVDecoder.class);
    
	/**
	 * @see com.skymobi.bean.tlv.TLVDecoder#decode(int, byte[], com.skymobi.bean.tlv.TLVDecodeContext)
	 */
	public Object decode(int tlvLength, byte[] tlvValue, TLVDecodeContext ctx) {
		if ( tlvLength == tlvValue.length ) {
			return tlvValue;
		}
		
		return	ArrayUtils.subarray(tlvValue, 0, tlvLength);
	}
	
	public Class<?>[] getFieldType() {
		return new Class<?>[]{byte[].class};
	}

}
